"""
本代码由[Tkinter布局助手]生成
官网:https://www.pytk.net
QQ交流群:905019785
在线反馈:https://support.qq.com/product/618914
"""
import re
import threading
import tkinter as tk
import uuid
from tkinter import *
from tkinter import font
from tkinter.ttk import *
from ttkbootstrap import DateEntry
from Crypto.Cipher import AES
from binascii import a2b_hex

from DBPool import MySQL


class WinGUI(Tk):
    def __init__(self):
        super().__init__()
        self.__win()
        self.tk_meun = self.__tk_meun(self)
        self.tk_table_video = self.__tk_table_video(self)
        self.tk_label_log = self.__tk_label_log(self)
        self.tk_label_frame_operation = self.__tk_label_frame_operation(self)
        self.tk_label_frame_desc = self.__tk_label_frame_desc(self.tk_label_frame_operation)
        self.tk_label_keyword = self.__tk_label_keyword(self.tk_label_frame_operation)
        self.tk_input_keywordInput = self.__tk_input_keywordInput(self.tk_label_frame_operation)
        self.tk_label_videoPage = self.__tk_label_videoPage(self.tk_label_frame_operation)
        self.tk_input_pageStart = self.__tk_input_pageStart(self.tk_label_frame_operation)
        self.tk_input_pageEnd = self.__tk_input_pageEnd(self.tk_label_frame_operation)
        self.tk_label_sleep = self.__tk_label_sleep(self.tk_label_frame_operation)
        self.tk_input_sleepInput = self.__tk_input_sleepInput(self.tk_label_frame_operation)
        self.tk_label_videoId = self.__tk_label_videoId(self.tk_label_frame_operation)
        self.tk_input_videoIdInput = self.__tk_input_videoIdInput(self.tk_label_frame_operation)
        self.tk_button_startVideo = self.__tk_button_startVideo(self.tk_label_frame_operation)
        self.tk_button_startComment = self.__tk_button_startComment(self.tk_label_frame_operation)
        self.tk_label_filter = self.__tk_label_filter(self.tk_label_frame_operation)
        self.tk_input_filterInput = self.__tk_input_filterInput(self.tk_label_frame_operation)
        self.tk_label_commentPage = self.__tk_label_commentPage(self.tk_label_frame_operation)
        self.tk_input_commentStart = self.__tk_input_commentStart(self.tk_label_frame_operation)
        self.tk_input_commentEnd = self.__tk_input_commentEnd(self.tk_label_frame_operation)
        self.tk_button_follow = self.__tk_button_follow(self.tk_label_frame_operation)
        self.tk_button_msg = self.__tk_button_msg(self.tk_label_frame_operation)
        self.tk_button_config = self.__tk_button_config(self.tk_label_frame_operation)
        self.tk_button_login = self.__tk_button_login(self.tk_label_frame_operation)
        self.tk_table_comment = self.__tk_table_comment(self)
        self.tk_button_refresh = self.__tk_button_refresh(self)
        self.tk_select_box_date = self.__tk_select_box_date(self)
        self.tk_label_frame_message = self.__tk_label_frame_message(self)
        self.tk_label_frame_customText = self.__tk_label_frame_customText(self.tk_label_frame_message)
        self.tk_text_customTextInput = self.__tk_text_customTextInput(self.tk_label_frame_customText)
        self.tk_label_frame_messageTemplate = self.__tk_label_frame_messageTemplate(self.tk_label_frame_message)
        self.tk_table_messageTemplateList = self.__tk_table_messageTemplateList(self.tk_label_frame_messageTemplate)
        self.tk_button_addMSg = self.__tk_button_addMSg(self.tk_label_frame_message)
        self.tk_button_delMsg = self.__tk_button_delMsg(self.tk_label_frame_message)
        self.tk_label_frame_messageNum = self.__tk_label_frame_messageNum(self.tk_label_frame_message)
        self.tk_label_followCount = self.__tk_label_followCount(self.tk_label_frame_messageNum)
        self.tk_label_messageCount = self.__tk_label_messageCount(self.tk_label_frame_messageNum)

    def __win(self):
        self.title("抖音获客关注私信平台")
        # 设置窗口大小、居中
        width = 1280
        height = 600
        screenwidth = self.winfo_screenwidth()
        screenheight = self.winfo_screenheight()
        geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
        self.geometry(geometry)

        self.minsize(width=width, height=height)

    def scrollbar_autohide(self, vbar, hbar, widget):
        """自动隐藏滚动条"""

        def show():
            if vbar: vbar.lift(widget)
            if hbar: hbar.lift(widget)

        def hide():
            if vbar: vbar.lower(widget)
            if hbar: hbar.lower(widget)

        hide()
        widget.bind("<Enter>", lambda e: show())
        if vbar: vbar.bind("<Enter>", lambda e: show())
        if vbar: vbar.bind("<Leave>", lambda e: hide())
        if hbar: hbar.bind("<Enter>", lambda e: show())
        if hbar: hbar.bind("<Leave>", lambda e: hide())
        widget.bind("<Leave>", lambda e: hide())

    def v_scrollbar(self, vbar, widget, x, y, w, h, pw, ph):
        widget.configure(yscrollcommand=vbar.set)
        vbar.config(command=widget.yview)
        vbar.place(relx=(w + x) / pw, rely=y / ph, relheight=h / ph, anchor='ne')

    def h_scrollbar(self, hbar, widget, x, y, w, h, pw, ph):
        widget.configure(xscrollcommand=hbar.set)
        hbar.config(command=widget.xview)
        hbar.place(relx=x / pw, rely=(y + h) / ph, relwidth=w / pw, anchor='sw')

    def create_bar(self, master, widget, is_vbar, is_hbar, x, y, w, h, pw, ph):
        vbar, hbar = None, None
        if is_vbar:
            vbar = Scrollbar(master)
            self.v_scrollbar(vbar, widget, x, y, w, h, pw, ph)
        if is_hbar:
            hbar = Scrollbar(master, orient="horizontal")
            self.h_scrollbar(hbar, widget, x, y, w, h, pw, ph)
        self.scrollbar_autohide(vbar, hbar, widget)

    def __tk_table_video(self, parent):
        # 表头字段 表头宽度
        columns = {"序号": 66, "标题": 224, "用户名": 112, "是否采集过评论": 112, "评论数": 56, "点赞数": 56,
                   "播放数": 56,
                   "分享数": 56, "收藏数": 56, "转发数": 56, "采集时间": 112, "用户id": 56, "视频ID": 56}
        tk_table = Treeview(parent, show="headings", columns=list(columns), )
        for text, width in columns.items():  # 批量设置列属性
            tk_table.heading(text, text=text, anchor='center')
            tk_table.column(text, anchor='center', width=width, stretch=False)  # stretch 不自动拉伸

        tk_table.place(relx=0.0164, rely=0.0650, relwidth=0.4383, relheight=0.6400)
        self.create_bar(parent, tk_table, True, True, 21, 39, 561, 384, 1280, 600)
        return tk_table

    def __tk_label_log(self, parent):
        label = Label(parent, text="日志", anchor="center", )
        # 设置字体，加粗
        bold_font = font.Font(family="Helvetica", size=12, weight="bold")
        # 设置文本颜色为红色
        label.config(font=bold_font, foreground="red")
        label.place(relx=0.0727, rely=0.0083, relwidth=0.5977, relheight=0.0500)
        return label

    def __tk_label_frame_operation(self, parent):
        frame = LabelFrame(parent, text="配置区", )
        frame.place(relx=0.0117, rely=0.7083, relwidth=0.4414, relheight=0.2833)
        return frame

    def __tk_label_frame_desc(self, parent):
        frame = LabelFrame(parent, text="说明区", )
        frame.place(relx=1.7221, rely=2.4765, relwidth=0.5044, relheight=0.9941)
        return frame

    def __tk_label_keyword(self, parent):
        label = Label(parent, text="关键词：", anchor="center", )
        label.place(relx=0.0177, rely=0.2353, relwidth=0.1062, relheight=0.1765)
        return label

    def __tk_input_keywordInput(self, parent):
        ipt = Entry(parent, )
        ipt.place(relx=0.1416, rely=0.2353, relwidth=0.4690, relheight=0.1765)
        return ipt

    def __tk_label_videoPage(self, parent):
        label = Label(parent, text="视频页数：", anchor="center", )
        label.place(relx=0.4071, rely=0.0000, relwidth=0.1009, relheight=0.1824)
        return label

    def __tk_input_pageStart(self, parent):
        ipt = Entry(parent, state='readonly')
        ipt.place(relx=0.5310, rely=0.0000, relwidth=0.1062, relheight=0.1765)
        return ipt

    def __tk_input_pageEnd(self, parent):
        ipt = Entry(parent, state='readonly')
        ipt.place(relx=0.6549, rely=0.0000, relwidth=0.1062, relheight=0.1765)
        return ipt

    def __tk_label_sleep(self, parent):
        label = Label(parent, text="采集延时：", anchor="center", )
        label.place(relx=0.0177, rely=0.0000, relwidth=0.1062, relheight=0.1765)
        return label

    def __tk_input_sleepInput(self, parent):
        ipt = Entry(parent, state='readonly')
        ipt.place(relx=0.1381, rely=0.0000, relwidth=0.2478, relheight=0.1765)
        return ipt

    def __tk_label_videoId(self, parent):
        label = Label(parent, text="视频ID", anchor="center", )
        label.place(relx=0.0177, rely=0.4706, relwidth=0.1062, relheight=0.1765)
        return label

    def __tk_input_videoIdInput(self, parent):
        ipt = Entry(parent, state='readonly')
        ipt.place(relx=0.1416, rely=0.4706, relwidth=0.2478, relheight=0.1765)
        return ipt

    def __tk_button_startVideo(self, parent):
        btn = Button(parent, text="采集视频", takefocus=False, )
        btn.place(relx=0.6283, rely=0.2353, relwidth=0.1416, relheight=0.1765)
        return btn

    def __tk_button_startComment(self, parent):
        btn = Button(parent, text="采集评论", takefocus=False, )
        btn.place(relx=0.6283, rely=0.6941, relwidth=0.1416, relheight=0.1765)
        return btn

    def __tk_label_filter(self, parent):
        label = Label(parent, text="过滤条件(模糊)", anchor="center", )
        label.place(relx=0.0177, rely=0.6882, relwidth=0.1469, relheight=0.1765)
        return label

    def __tk_input_filterInput(self, parent):
        ipt = Entry(parent, )
        ipt.place(relx=0.1770, rely=0.6941, relwidth=0.4425, relheight=0.1765)
        return ipt

    def __tk_label_commentPage(self, parent):
        label = Label(parent, text="评论页数：", anchor="center", )
        label.place(relx=0.4071, rely=0.4706, relwidth=0.1009, relheight=0.1824)
        return label

    def __tk_input_commentStart(self, parent):
        ipt = Entry(parent, state='readonly')
        ipt.place(relx=0.5310, rely=0.4706, relwidth=0.1062, relheight=0.1765)
        return ipt

    def __tk_input_commentEnd(self, parent):
        ipt = Entry(parent, state='readonly')
        ipt.place(relx=0.6549, rely=0.4706, relwidth=0.1062, relheight=0.1765)
        return ipt

    def __tk_button_follow(self, parent):
        btn = Button(parent, text="关注", takefocus=False, )
        btn.place(relx=0.7788, rely=0.2353, relwidth=0.1770, relheight=0.1765)
        return btn

    def __tk_button_msg(self, parent):
        btn = Button(parent, text="私信", takefocus=False, )
        btn.place(relx=0.7788, rely=0.4706, relwidth=0.1770, relheight=0.1765)
        return btn

    def __tk_button_config(self, parent):
        btn = Button(parent, text="保存配置", takefocus=False, )
        btn.place(relx=0.7788, rely=0.0000, relwidth=0.1770, relheight=0.1765)
        return btn

    def __tk_button_login(self, parent):
        btn = Button(parent, text="账号登录", takefocus=False, )
        btn.place(relx=0.7788, rely=0.6941, relwidth=0.1770, relheight=0.1765)
        return btn

    def __tk_table_comment(self, parent):
        # 表头字段 表头宽度
        columns = {"序号": 66, "评论时间": 133, "评论内容": 334, "评论点赞": 66, "评论用户IP": 66, "是否关注": 66,
                   "是否私信": 66, "评论用户": 66,
                   "评论用户ID": 66, "采集时间": 133, "视频ID": 66, "评论ID": 66}
        tk_table = Treeview(parent, show="headings", columns=list(columns), )
        for text, width in columns.items():  # 批量设置列属性
            tk_table.heading(text, text=text, anchor='center')
            tk_table.column(text, anchor='center', width=width, stretch=False)  # stretch 不自动拉伸

        tk_table.place(relx=0.4609, rely=0.0650, relwidth=0.5227, relheight=0.6383)
        self.create_bar(parent, tk_table, True, True, 590, 39, 669, 383, 1280, 600)
        return tk_table

    def __tk_button_refresh(self, parent):
        btn = Button(parent, text="查询", takefocus=False, )
        btn.place(relx=0.9375, rely=0.0083, relwidth=0.0391, relheight=0.0500)
        return btn

    def __tk_select_box_date(self, parent):
        # 创建时间选择器组件
        cal = DateEntry(parent, width=12)
        cal.place(relx=0.8125, rely=0.0083, relwidth=0.1172, relheight=0.0500)
        return cal

    def __tk_label_frame_message(self, parent):
        frame = LabelFrame(parent, text="私信区", )
        frame.place(relx=0.4609, rely=0.7083, relwidth=0.5203, relheight=0.2833)
        return frame

    def __tk_label_frame_customText(self, parent):
        frame = LabelFrame(parent, text="自定义私信", )
        frame.place(relx=0.0075, rely=0.0000, relwidth=0.3453, relheight=0.8824)
        return frame

    def __tk_text_customTextInput(self, parent):
        text = Text(parent)
        text.place(relx=0.0348, rely=0.0133, relwidth=0.9130, relheight=0.8667)
        return text

    def __tk_label_frame_messageTemplate(self, parent):
        frame = LabelFrame(parent, text="私信模板", )
        frame.place(relx=0.3679, rely=0.0000, relwidth=0.3904, relheight=0.8824)
        return frame

    def __tk_table_messageTemplateList(self, parent):
        # 表头字段 表头宽度
        columns = {"私信类型": 74, "私信内容": 124, "是否启用": 49, "私信ID": 12}
        tk_table = Treeview(parent, show="headings", columns=list(columns), )
        for text, width in columns.items():  # 批量设置列属性
            tk_table.heading(text, text=text, anchor='center')
            tk_table.column(text, anchor='center', width=width, stretch=False)  # stretch 不自动拉伸

        tk_table.place(relx=0.0192, rely=0.2333, relwidth=0.9615, relheight=0.6333)
        self.create_bar(parent, tk_table, True, True, 5, 35, 250, 95, 260, 150)
        return tk_table

    def __tk_button_addMSg(self, parent):
        btn = Button(parent, text="添加私信", takefocus=False, )
        btn.place(relx=0.4580, rely=0.0882, relwidth=0.1051, relheight=0.1765)
        return btn

    def __tk_button_delMsg(self, parent):
        btn = Button(parent, text="删除私信", takefocus=False, )
        btn.place(relx=0.6006, rely=0.0882, relwidth=0.1051, relheight=0.1765)
        return btn

    def __tk_label_frame_messageNum(self, parent):
        frame = LabelFrame(parent, text="关注私信个数", )
        frame.place(relx=0.7733, rely=0.0000, relwidth=0.2102, relheight=0.8824)
        return frame

    def __tk_label_followCount(self, parent):
        label = Label(parent, text="关注个数", anchor="center", )
        label.place(relx=0.2143, rely=0.1067, relwidth=0.6429, relheight=0.2000)
        return label

    def __tk_label_messageCount(self, parent):
        label = Label(parent, text="私信个数", anchor="center", )
        label.place(relx=0.2143, rely=0.5333, relwidth=0.6429, relheight=0.2000)
        return label

    # 菜单说明
    def __tk_meun(self, parent):
        menubar = Menu(parent)
        aboutmemu = Menu(menubar, tearoff=0, bg='lightblue', fg='blue')
        menubar.add_cascade(label='关于', menu=aboutmemu)
        aboutmemu.add_command(label='软件说明', command=self.show_Description)
        aboutmemu.add_command(label='版本', command=self.show_Version)
        aboutmemu.add_command(label='开发者', command=self.show_Developer)
        aboutmemu.add_command(label='授权信息', command=self.show_Authorization)
        aboutmemu.add_command(label='请求信息', command=self.show_RequestParams)
        parent.config(menu=menubar)
        return aboutmemu

    def show_Description(self):
        Description(self)

    def show_Version(self):
        Version(self)

    def show_Developer(self):
        Developer(self)

    def show_Authorization(self):
        Authorization(self)

    def show_RequestParams(self):
        RequestParams(self)


# 使用说明界面
class Description():
    """
        软件描述说明介绍界面
    """

    def __init__(self, master):
        self.master = master
        self.window = tk.Toplevel(master)
        self.window.wm_attributes('-topmost', 1)
        sw = self.window.winfo_screenwidth()
        sh = self.window.winfo_screenheight()
        ww = 800
        wh = 350
        x = (sw - ww) / 3
        y = (sh - wh) / 3
        self.window.geometry('%dx%d+%d+%d' % (ww, wh, x, y))  # 父容器大小
        self.window.title('使用说明')
        self.create_page()

    def create_page(self):
        Dev = tk.LabelFrame(self.window, text="关于使用说明", padx=10, pady=5)  # 水平，垂直方向上的边距均为 10
        Dev.place(x=50, y=50)
        text = "【使用前仔细阅读使用说明】 \n" \
               "使用说明\n" \
               "需要开启定向浏览器获取平台登陆信息。\n" \
               "**注意事项**\n" \
               "- 浏览器属性中进行添加： chrome.exe --remote-debugging-port=5003 --user-data-dir='D:\selenumAutomationProfile''\n" \
               "- 获取数据失败需要进行账号登录重新获取用户信息。\n"
        tk.Label(Dev, text=text, justify='left').grid(column=0, row=0, sticky='w', pady=5, padx=5)  # 添加用户账号


# 版本说明界面
class Version():
    """
    软件版本说明介绍界面
    """

    def __init__(self, master):
        self.master = master
        self.window = tk.Toplevel(master)
        self.window.wm_attributes('-topmost', 1)
        sw = self.window.winfo_screenwidth()
        sh = self.window.winfo_screenheight()
        ww = 375
        wh = 280
        x = (sw - ww) / 3
        y = (sh - wh) / 3
        self.window.geometry('%dx%d+%d+%d' % (ww, wh, x, y))  # 父容器大小
        self.window.title('软件版本')
        self.create_page()

    def create_page(self):
        Dev = tk.LabelFrame(self.window, text="关于版本更新", padx=10, pady=5)  # 水平，垂直方向上的边距均为 10
        Dev.place(x=50, y=50)
        text = " 2024-11-15 版本：V1.0\n "
        tk.Label(Dev, text=text).grid(column=0, row=0, sticky='w', pady=5, padx=5)  # 添加用户账号


# 开发者说明界面
class Developer():
    """
    软件开发者介绍界面
    """

    def __init__(self, master):
        self.master = master
        self.window = tk.Toplevel(master)
        self.window.wm_attributes('-topmost', 1)
        sw = self.window.winfo_screenwidth()
        sh = self.window.winfo_screenheight()
        ww = 375
        wh = 280
        x = (sw - ww) / 3
        y = (sh - wh) / 3
        self.window.geometry('%dx%d+%d+%d' % (ww, wh, x, y))  # 父容器大小
        self.window.title('开发者')
        self.create_page()

    def create_page(self):
        Dev = tk.LabelFrame(self.window, text="关于开发者", padx=10, pady=5)  # 水平，垂直方向上的边距均为 10
        Dev.place(x=50, y=50)
        text = " 作者：lcl\n" \
               " 技能：熟悉各项爬虫与反爬虫，数据清洗，\n         网站搭建，软件编写\n" \
               " 联系：18310722053\n"
        tk.Label(Dev, text=text, justify='left').grid(column=0, row=0, sticky='w', pady=5, padx=5)  # 添加用户账号


# 授权信息
class Authorization():
    def __init__(self, master):
        self.master = master
        self.window = tk.Toplevel(master)
        self.window.wm_attributes('-topmost', 1)
        sw = self.window.winfo_screenwidth()
        sh = self.window.winfo_screenheight()
        ww = 375
        wh = 280
        x = (sw - ww) / 3
        y = (sh - wh) / 3
        self.window.geometry('%dx%d+%d+%d' % (ww, wh, x, y))  # 父容器大小
        self.window.title('授权信息')
        self.create_page()

    def parse_license_file(self):
        """ 解析license文件 """
        license_dic = {}
        license_file = 'License.dat'

        try:
            with open(license_file, 'r') as LF:
                for line in LF.readlines():
                    if re.match('^\s*(\S+)\s*:\s*(\S+)\s*$', line):
                        my_match = re.match('^\s*(\S+)\s*:\s*(\S+)\s*$', line)
                        license_dic[my_match.group(1)] = my_match.group(2)
        except Exception as e:
            return {'code': '0', 'msg': '*License Error*: License文件不存在.', 'data': str(e)}

        return (license_dic)

    def decrypt(self, content):
        """ 解密license文件 """
        aesKey = b'2024052020240520'  # 加密与解密所使用的密钥，长度必须是16的倍数
        aesIv = b'2024052020240520'  # initial Vector,长度要与aesKey一致
        aesMode = AES.MODE_CBC  # 使用CBC模式

        aes = AES.new(aesKey, aesMode, aesIv)
        decrypted_content = aes.decrypt(a2b_hex(content.encode('utf-8')))

        return decrypted_content.decode('utf-8')

    def create_page(self):
        Dev = tk.LabelFrame(self.window, text="软件授权信息", padx=10, pady=5)  # 水平，垂直方向上的边距均为 10
        Dev.place(x=50, y=50)

        license_dic = self.parse_license_file()
        sign = self.decrypt(license_dic['Sign'])

        sign_list = sign.split('#')
        mac = sign_list[0].strip()
        date = sign_list[1].strip()
        text = f" 授权截止时间：{date}\n" \
               f" 授权主机MAC信息：{mac}\n"
        tk.Label(Dev, text=text, justify='left').grid(column=0, row=0, sticky='w', pady=5, padx=5)  # 添加用户账号


# 请求信息
class RequestParams():
    def __init__(self, master):
        self.master = master
        self.mysql = MySQL()
        self.window = tk.Toplevel(master)
        self.window.wm_attributes('-topmost', 1)
        sw = self.window.winfo_screenwidth()
        sh = self.window.winfo_screenheight()
        ww = 750
        wh = 600
        x = (sw - ww) / 3
        y = (sh - wh) / 3
        self.window.geometry('%dx%d+%d+%d' % (ww, wh, x, y))  # 父容器大小
        self.window.title('请求信息')
        self.create_page()
        self.initData()

    def get_mac(self):
        """ 获取服务器MAC地址 """
        mac = uuid.UUID(int=uuid.getnode()).hex[-12:]
        return ":".join([mac[e:e + 2] for e in range(0, 11, 2)])

    def initData(self):
        host = self.get_mac()
        sql_select_all = f'select * from `request_info` where host = %s'
        results = self.mysql.select_all(sql_select_all, host)
        if len(results) > 0:
            for result in results:
                self.contentEntry.delete("1.0", tk.END)  # 清空文本框
                if result['content'] is None:
                    value = ''
                else:
                    value = result['content']
                self.contentEntry.insert("1.0", value)

    def create_page(self):
        res = tk.LabelFrame(self.window, text="关于请求信息", padx=10, pady=5)  # 水平，垂直方向上的边距均为 10
        res.place(x=50, y=50)
        self.contentEntry = tk.Text(res)
        self.contentEntry.grid(column=0, row=0, sticky='w', pady=5, padx=5)
        tk.Button(res, text="保存", command=self.add_param).grid(columnspan=2, row=3, pady=5, ipadx=10)

    def add_param(self):
        host = self.get_mac()
        sql_select_all = f'select * from `request_info` where host = %s'
        results = self.mysql.select_all(sql_select_all, host)
        if len(results) > 0:
            content = self.contentEntry.get("1.0", "end-1c")
            sql = f'UPDATE request_info SET content=%s, host=%s where id = %s'
            self.mysql.insert_one(sql, (content, host, results[0]['id']))
            self.window.destroy()
        else:
            content = self.contentEntry.get("1.0", "end-1c")
            if content != '':
                sql = f'INSERT INTO request_info (content, host) VALUES (%s, %s)'
                self.mysql.insert_one(sql, (content, host))
                self.window.destroy()
                print('添加成功')
            else:
                print('参数不能为空')


class Win(WinGUI):
    def __init__(self, controller):
        self.ctl = controller
        super().__init__()
        self.__event_bind()
        self.__style_config()
        self.ctl.init(self)

    def __event_bind(self):
        self.tk_table_video.bind('<<TreeviewSelect>>', lambda event: self.run_async(self.ctl.selectVideo, event))
        self.tk_table_video.bind('<Button-1>', lambda event: self.run_async(self.ctl.clickVideo, event))
        self.tk_button_startVideo.bind('<Button-1>', lambda event: self.run_async(self.ctl.spiderVideo, event))
        self.tk_button_startComment.bind('<Button-1>', lambda event: self.run_async(self.ctl.spiderComment, event))
        self.tk_button_addMSg.bind('<Button-1>', lambda event: self.run_async(self.ctl.addMessage, event))
        self.tk_button_delMsg.bind('<Button-1>', lambda event: self.run_async(self.ctl.delMessage, event))
        self.tk_button_config.bind('<Button-1>', lambda event: self.run_async(self.ctl.config, event))
        self.tk_table_comment.bind('<<TreeviewSelect>>', lambda event: self.run_async(self.ctl.selectComment, event))
        self.tk_table_comment.bind('<Button-1>', lambda event: self.run_async(self.ctl.clickComment, event))
        self.tk_button_follow.bind('<Button-1>', lambda event: self.run_async(self.ctl.sendFollow, event))
        self.tk_button_msg.bind('<Button-1>', lambda event: self.run_async(self.ctl.sendMsg, event))
        self.tk_button_login.bind('<Button-1>', lambda event: self.run_async(self.ctl.login, event))
        self.tk_button_refresh.bind('<Button-1>', lambda event: self.run_async(self.ctl.refresh, event))
        pass

    def __style_config(self):
        pass

    def run_async(self, func, *args):
        thread = threading.Thread(target=func, args=args)
        thread.start()


if __name__ == "__main__":
    win = WinGUI()
    win.mainloop()
